package com.ruoyi.eqmonitor.dispose;//package io.zhsw.modules.mqtt;

import com.ruoyi.eqmonitor.dispose.service.MqttService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * 设备消息订阅
 *
 * @author dh
 */
@Slf4j
@Component
@Order(value = 2)
public class SubscribeSample implements CommandLineRunner {

    @Resource
    private MqttService mqttService;

    @Value("${mqtt.enable:false}")
    private boolean enableMqtt;

    @Override
    public void run(String... args) {
        if (enableMqtt) {
            // 订阅消息
            mqttService.subScription();
            // 监听设备状态变化
            mqttService.listenDeviceCodeChange();
        }
    }

}
